﻿using UnityEngine;
using System.Collections;

public class RoController : MonoBehaviour {
	public float tocdo=2;
	bool left,right;
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
		DiChuyen ();
	}

	void DiChuyen ()
	{
		if (transform.position.x < -8.9f)
						left = false;
		if (transform.position.x > -8.9f)
						left = true;
		if (transform.position.x < 9.09f)
						right = true;
		if (transform.position.x > 9.09f)
						right = false;
			
		if (Input.GetKey ("a")) {
			if(left)
						transform.Translate (Vector3.left * tocdo * Time.deltaTime);
				}
		if (Input.GetKey ("d") & right == true) {
			if(right)
						transform.Translate (Vector3.right * tocdo * Time.deltaTime);
				}

	}
}
